<template>
	<view class="ident">
		<view class="header">
			<image @click="handleBack" src="https://oss-shop.cciinet.com/files/MiniProgram/back1.svg"></image>
			<view class="title" @click="handleJump">跳过</view>
		</view>
		<view class="h1">名片或营业执照</view>
		<view class="upload" @click="handleChooseImg">
			<image src="https://oss-shop.cciinet.com/files/MiniProgram/license_bg.png" v-if="!img" class="img" mode="widthFix"></image>
			<image :src="img" v-if="img" class="img1" mode=""></image>
		</view>
		<view class="account_btn" @click="handleUpload">立即上传</view>
	</view>
</template>

<script>
	import {
		getUploadImage
	} from "@/api/common/index.js"
	import {
		getUpdateById
	} from "@/api/login/index.js"
	
	export default {
		data() {
			return {
				img: ""
			}
		},
		methods: {
			handleChooseImg() {
				uni.chooseImage({
					count: 1,
					// sizeType:  original 原图，compressed 压缩图，默认二者都有
					sizeType: "original",
					success: res => {
						let size = parseFloat(res.tempFiles[0].size/1024/1024).toFixed(2)
						if(size>10) {
							uni.showToast({
								title:'请上传10M以内的图片',
								icon:'none'
							})
							return
						}
						console.log(size)
						getUploadImage({
							file: res.tempFilePaths[0],
							formData: {
								'waterFlag': 'true'
							}
						}).then(response => {
							let data = JSON.parse(response)
							if (data.code == 0) {
								console.log(data.data.url)
								this.img = data.data.url
							}
						})
						// uni.previewImage({
						// 	// 对选中的图片进行预览
						// 	urls: res.tempFilePaths,
						// })
					}
				});
			},
			handleBack() {
				this.$handleOpenUrl("",2)
			},
			handleUpload() {
				getUpdateById({
					businessLicenseImage:this.img,
					examineType:0,
					id:uni.getStorageSync('userId')
				}).then(res=>{
					if(res.code == 0) {
						uni.switchTab({
							url:'/pages/home/index'
						})
					}
				})
			},
			handleJump() {
				uni.switchTab({
					url:'/pages/home/index'
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F7F9FE;
	}
</style>

<style lang="scss" scoped>
	.ident {
		height: 90vh;
		margin: 24upx 30upx;
		background: #FFFFFF;
		border-radius: 16upx;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-left: 26upx;
			margin-right: 26upx;
			padding-top: 28upx;

			image {
				width: 49upx;
				height: 49upx;
			}

			.title {
				font-size: 32upx;
				color: #333333;
			}
		}

		.h1 {
			margin-top: 52upx;
			margin-left: 54upx;
			font-size: 32upx;
			color: #333333;

		}

		.upload {
			margin: 31upx 55upx 105upx 55upx;
			height: 241upx;
			background: #FEFEFE;
			border: 1upx solid #CCCCCC;
			display: flex;
			justify-content: center;
			align-items: center;

			.img {
				width: 167upx;
			}

			.img1 {
				width: 100%;
				height: 241upx;
			}
		}

		.account_btn {
			display: block;
			width: 520upx;
			height: 88upx;
			line-height: 88upx;
			background: linear-gradient(87deg, #035ABE, #218EED);
			border-radius: 44upx;
			color: #ffffff;
			text-align: center;
			font-size: 34upx;
			margin: 60upx auto 17upx;
		}
	}
</style>
